home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Games / NeXTmj / Source / IntegerList.cc < prev    next >
Text File  |  1991-03-22  |  1KB  |  105 lines

  1.  
  2. /*
  3.  $Author$
  4.  $Header$
  5.  *
  6.  $Log$
  7.  */
  8.  
  9. #import    "IntegerList.h"
  10.  
  11. extern "C" {
  12. #import    <assert.h>
  13.  
  14. #import    "mj.h"
  15. }
  16.  
  17.                                                 // All integers on the list are offseted
  18.                                                 //    by this amount.
  19. #define    OFFSET    1000
  20.  
  21.  
  22. IntegerList::IntegerList( void ) {
  23.  
  24.  
  25.     my_list        = [[ List alloc ] init ];
  26.     iterator = 0;
  27. }
  28.  
  29.  
  30. IntegerList::~IntegerList( void ) {
  31.  
  32.  
  33.     [ my_list free ];
  34. }
  35.  
  36.  
  37. int IntegerList::operator()() {
  38.  
  39.     int    rVal = -1;
  40.     
  41.     
  42.     if( [ my_list count ] > iterator )
  43.         rVal = decodeValue(( int )[ my_list objectAt:iterator++ ]);
  44.     
  45.     return rVal;
  46. }
  47.  
  48.  
  49. void IntegerList::beginIterate( void ) {
  50.  
  51.  
  52.     iterator = 0;
  53. }
  54.  
  55.  
  56. void IntegerList::operator+=( int integer ) {
  57.  
  58.  
  59.     [ my_list addObject:( id )encodeValue( integer ) ];
  60. }
  61.  
  62.  
  63. void IntegerList::operator-=( int integer ) {
  64.  
  65.  
  66.     [ my_list removeObject:( id )encodeValue( integer ) ];
  67. }
  68.  
  69.  
  70. void IntegerList::empty( void ) {
  71.  
  72.  
  73.     [ my_list empty ];
  74. }
  75.  
  76.  
  77. int IntegerList::count( void ) {
  78.  
  79.  
  80.     return [ my_list count ];
  81. }
  82.  
  83.  
  84. int IntegerList::lastValue( void ) {
  85.  
  86.  
  87.     return count() == 0 ? -1 : decodeValue(( int )[ my_list lastObject ]);
  88. }
  89.  
  90.  
  91. int IntegerList::encodeValue( int integer ) {
  92.  
  93.  
  94.     return integer + OFFSET;
  95. }
  96.  
  97.  
  98. int IntegerList::decodeValue( int integer ) {
  99.  
  100.  
  101.     return integer - OFFSET;
  102. }
  103.  
  104.  
  105.